﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;
using QuickTest.Core.Events;
using QuickTest.Core.ServiceInterfaces;
using QuickTest.Core.TestRunner;
using QuickTest.Core.Threading;
using QuickTest.Services.Packaging;
using QuickTest.Services.TestRunner;
using Rhino.Mocks;

namespace QuickTest.Tests.Services.Packaging
{
    [TestFixture]
    public class TestRunnerServiceTests
    {
        [Test]
        public void RunTests_should_raise_execute_test_run_event()
        {
            var threadingProvider = new NoThreadingProvider();
            var eventHub = MockRepository.GenerateStub<IEventHub>();

            var testRunnerService = new TestRunnerServiceStub(threadingProvider, eventHub);
            var testRunner = MockRepository.GenerateStub<IRunsTests>();

            testRunnerService.RunTests(testRunner, string.Empty, string.Empty);

            eventHub.AssertWasCalled(e => e.RaiseTestRunExecuted(Arg<EventArgs>.Is.Anything));
        }
    }

    internal class TestRunnerServiceStub : TestRunnerService
    {
        public TestRunnerServiceStub(IThreadingProvider threadingProvider, IEventHub eventHub)
            : base(threadingProvider, eventHub)
        {
        }

        protected override ITestPackageService GetTestPackageService(string solutionPath, string outputDirectory)
        {
            var testPackageService = MockRepository.GenerateStub<ITestPackageService>();
            testPackageService.Stub(s => s.CreateTestPackage(string.Empty))
                .Return(MockRepository.GenerateStub<ITestPackage>())
                .IgnoreArguments();
            return testPackageService;
        }
    }
}
